import React, {FC, useContext} from 'react';
import {Form, Input} from "antd";
import {KfQuickForm} from "kf-web-library";
import * as API from "@/services";
import {FormattedMessage} from "umi";
import {useIntl} from "@@/exports";
import {HxConfigContext} from "@/layouts/HxConfigContext";

interface PasswordModifyFormProps {
}

const PasswordModifyForm: FC<PasswordModifyFormProps> = (props) => {
  const intl= useIntl();
  const {isZhCN} = useContext(HxConfigContext)
  return (
    <KfQuickForm
      formType={"passwordModify"}
      submitButtonText={<FormattedMessage id="text.submit"/>}
      formProps={{
        className: "password-modify-form",
        labelCol: {
          flex: isZhCN ?'0 0 120px': '0 0 140px'
        },
        wrapperCol: {
          flex: "1"
        },
      }}
      submitRequest={{
        passwordModify: (formValues) => {
          return API.modifyPwd(formValues);
        }
      }}
    >
      <Form.Item label={<FormattedMessage id={`text.current-pwd`}/>}
                 name={"oldPasswd"}
                 rules={[{required: true}]}
      >
        <Input.Password size={"large"}/>
      </Form.Item>
      <Form.Item label={<FormattedMessage id={`text.new-pwd`}/>}
                 name={"newPasswd"}
                 rules={[
                   {
                     required: true,
                     //pattern: /^.*(?=.+)(?=.*\d)(?=.*[a-zA-Z])(?=.*[~!@#$%^&*()_.]).{6,32}$/,
                     //message: '密码必须包含大写字母、数字、特殊字符且至少6位',
                   },
                 ]}
      >
        <Input.Password size={"large"}/>
      </Form.Item>
    </KfQuickForm>
  );
};

export default PasswordModifyForm;
